package com.kch.system.service.impl;

import com.kch.system.domain.Activity;
import com.kch.system.mapper.ActivityMapper;
import com.kch.system.service.IActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ActivityServiceImpl implements IActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public List<Activity> selectMeetingPage(Activity activity) {
        return activityMapper.selectMeetingPage(activity);
    }

    @Override
    public int updateStatus(Integer id) {
        Activity activity = activityMapper.selectByPrimaryKey(id);
        String status = ("0".equals(activity.getStatus())? "1" : "0");
        return activityMapper.updateStatus(activity.getId(), status);
    }

    @Override
    public int insertSysActivity(Activity activity) {
        activity.setStatus("1");
        activity.setCreateTime(new Date());
        return activityMapper.insert(activity);
    }

    @Override
    public int deleteActivity(String ids) {
        return activityMapper.deleteByPrimaryKey(Integer.valueOf(ids));
    }

    @Override
    public Activity selectById(Integer id) {
        return activityMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateById(Activity activity) {
        Activity exist = activityMapper.selectByPrimaryKey(activity.getId());
        activity.setCreateBy(exist.getCreateBy());
        activity.setCreateTime(exist.getCreateTime());
        activity.setStatus(exist.getStatus());
        return activityMapper.updateByPrimaryKeyWithBLOBs(activity);
    }
}
